package logic

import (
	"web_app/dao/mysql"
	"web_app/modules"
)

func CreatePost(p *modules.Post) error {

	return mysql.CreatePost(p)
}
func GetPostDetail(postId int64) *modules.ApiPostDetail {

	post, err := mysql.FindPostByID(postId)
	if err != nil {
		return nil
	}
	AuthorName, err := mysql.FindUserById(post.AuthorID)
	if err != nil {
		return nil
	}
	var community modules.Community
	mysql.GetCommunityById(&community, post.CommunityID)
	var result modules.ApiPostDetail
	result.Post = post
	result.AuthorName = AuthorName
	result.Community = &community

	return &result
}
